//||=========================================================================||
//||                                                                         ||
//||                               MolDynSys.h                               ||
//||                                                                         ||
//||                           by the_best_goose))                           ||
//||                                                                         ||
//||=========================================================================||

#include <stdio.h>

#ifndef MOL_DYN_SYS_H
#define MOL_DYN_SYS_H

//-----------------------------------------------------------------------------

enum Tests{ NO_TEST = 0,
            ONE_PARTICLE,
            TWO_PARTICLES,
            THREE_PARTICLES,
            MANY_PARTICLES};

//-----------------------------------------------------------------------------

class MolDynSys
{
    public:

    MolDynSys(unsigned int part_count, float density, Tests test = NO_TEST);
    ~MolDynSys();

    void InitSystem();
    void Relax(float temperature_eps, float step);
    void RunThermostat(float T, float eps, float step);
    void NextStep(float t);

    float CountKinEnergy();

    void EnableThermostat();
    void DisableThermostat();

    void SetTemperatureUpTime(float up_time);
    
    float GetTemperature();
    float GetKinEnergy();
    float GetPotEnergy();
    float GetEnergy();

    void Test(Tests test);
    void Print();

    private:

    void Init(int part_count);
    void Destroy();

    inline void CountForces();

    inline float Dist2(int i, int j);
    inline void NullArray(float** arr);

    void UseThermostat(float t);

    float* coords_[3];
    float* vels_[3];
    float* forces_[3];
    unsigned int part_count_;

    float size_[3];

    float energy_kin_;
    float energy_pot_;
    
    bool thermostat_status_;
    float need_temperature_;
    float current_temperature_;
    float temperature_temp_;
    int last_temperature_update_;
    
    int temperature_up_time_;

    FILE* plog_;

    static const float r_cr2_ = 16;

    static const float k_bolc = 1;
    static const float eps = 1;
    static const float sigma = 1;

};

//-----------------------------------------------------------------------------

#endif //MOL_DYN_SYS_H
